﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;

namespace EarringsRecommendationWeb
{
    public class ShapeManagement
    {
        private Dictionary<int, Point> _PointCol = null;

        public ShapeManagement(Dictionary<int, Point> pointCol)
        {
            _PointCol = pointCol;
        }

        private int _faceLength;
        /// <summary>
        /// Get ความยาวของใบหน้า (Face Lenght) Point 1,10
        /// </summary>
        public int FaceLength
        {
            get { return GetDistance(_PointCol[1],_PointCol[10]); }
            set { _faceLength = value; }
        }

        private int _faceWidth;
        /// <summary>
        /// Get ความกว้างของใบหน้า (Face Width) Point 4,5 
        /// </summary>
        public int FaceWidth
        {
            get { return  GetDistance(_PointCol[4],_PointCol[5]); }
            set { _faceWidth = value; }
        }

        private int _forehead;
        /// <summary>
        /// Get ความกว้างของหน้าผาก (Forehead) Point 2,3
        /// </summary>
        public int Forehead
        {
            get { return GetDistance(_PointCol[2], _PointCol[3]); }
            set { _forehead = value; }
        }

        private int _cheekbones;
        /// <summary>
        /// Get ความกว้างของโหนกแก้ม(Cheekbones) Point 6,7
        /// </summary>
        public int Cheekbones
        {
            get { return GetDistance(_PointCol[6], _PointCol[7]);; }
            set { _cheekbones = value; }
        }

        private int _jawLength;
        /// <summary>
        /// Get ความกว้างของกราม (Jaw) Point 8,9
        /// </summary>
        public int JawLength
        {
            get { return GetDistance(_PointCol[8], _PointCol[9]); }
            set { _jawLength = value; }
        }

        private int _neckLength;
        /// <summary>
        /// Get ความยาวของคอ (NeckLength) Point 10,13,14
        /// </summary>
        public int NeckLength
        {
            get 
            {

                double nY = (_PointCol[13].Y + _PointCol[14].Y) / 2;
                double nX = _PointCol[10].X;
                Point pNeck = new Point(Convert.ToInt32(nX),Convert.ToInt32(nY));

                
                return GetDistance(_PointCol[10],pNeck); 
            }
            set { _neckLength = value; }
        }

        public string GetEarlobePosition()
        {
            string Right = _PointCol[11].X.ToString() + "," + _PointCol[11].Y.ToString();
            string Left = _PointCol[12].X.ToString() + "," + _PointCol[12].Y.ToString();

            string valueReturn = Right + ":" + Left;

            return valueReturn;
        }

        public string GetRightEarlobePosition()
        {
            string Right = _PointCol[11].X.ToString() + "," + _PointCol[11].Y.ToString();
            return Right;
        }

        public string GetLeftEarlobePosition()
        {
            string Left = _PointCol[12].X.ToString() + "," + _PointCol[12].Y.ToString();
            return Left;
        }
        /// <summary>
        /// หาความยาวระหว่าง Point 2 Point
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        private int GetDistance(Point p1, Point p2)
        {
            int dist = Convert.ToInt32(Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2)));
            return dist;
        }
    }
}